package com.gesee.zyspps.adapter;

import java.util.ArrayList;
import java.util.List;

import com.gesee.zys.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gesee.zyspps.adapter.GridViewAdapter.ViewHolder;
import com.gesee.zyspps.db.CmsFeature;
import com.gesee.zyspps.db.CmsPipelineField;
import com.gesee.zyspps.db.CmsPointsName;

public class TeZhengAdapter extends BaseAdapter
{
    
    private Context mContext;
    private LayoutInflater mInflater;
    private List<CmsFeature> list = new ArrayList<CmsFeature>();
    private int selectedPosition = -1;// 选中的位置
    
    public TeZhengAdapter(Context context){
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount()
    {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public CmsFeature getItem(int arg0)
    {
        // TODO Auto-generated method stub
        return list.get(arg0);
    }
    
    public void addData(List<CmsFeature> list){
        this.list.addAll(list);
        notifyDataSetChanged();
    }
    
    public void cleanData(){
        this.list.clear();
        notifyDataSetChanged();
    }

    public void setSelectedPosition(int position) {    
        selectedPosition = position;    
    }  
    
    
    @Override
    public long getItemId(int arg0)
    {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int arg0, View convertView, ViewGroup arg2)
    {
        // TODO Auto-generated method stub
        CmsFeature cms = list.get(arg0);
        ViewHolder holder = null;
        if(convertView == null){
            convertView = mInflater.inflate(R.layout.item_main_spinner,null);
            holder = new ViewHolder();
            holder.data = (TextView) convertView.findViewById(R.id.data);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.data.setText(cms.toString());
        if (selectedPosition == arg0) {     
            convertView.setBackgroundColor(Color.BLUE);    
        } else {      
            convertView.setBackgroundColor(Color.TRANSPARENT);       

        }
        return convertView;
    }
    
    static class ViewHolder{
        private TextView data;
    }

}
